#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244853;
typedef long long LL;
const int N = 2e6 + 10;

void solve() {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }

    map<int, int> cnt;
    for (int num : arr) {
        cnt[num]++;
    }
    vector<int> freqs;
    for (auto& p : cnt) {
        freqs.push_back(p.second);
    }
    int max_len = 0;
    for (int f : freqs) {
        int count = 0;
        for (int freq : freqs) {
            if (freq >= f) {
                count++;
            }
        }
        max_len = max(max_len, count * f);
    }
    cout << max_len << endl;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/*

 */